package com.juyu.miliao.api.controller;

import com.juyu.miliao.api.domain.UserCoverUrl;
import com.juyu.miliao.api.service.UserCoverUrlService;
import com.juyu.miliao.common.domain.Subject;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/user/coverUrl")
public class UserCoverUrlController {
    @Resource
    private UserCoverUrlService userCoverUrlService;
    /**
     * 我的-编辑个人资料-获取用户个人信息
     *
     * @param
     * @return
     */
    @GetMapping()
    public List<UserCoverUrl> getUserCoverUrlByUserId(Authentication token) {
        Subject subject = (Subject) token.getPrincipal();
        return userCoverUrlService.getUserCoverUrlByUserId(subject.getId());
    }

    /**
     * 删除用户私照
     */
    @DeleteMapping("/{id}")
    public void deleteUserCoverUrl(Authentication token, @PathVariable("id") int id) {
        Subject subject = (Subject) token.getPrincipal();
        userCoverUrlService.deleteUserCoverUrl(id, subject.getId());
    }

    /**
     * 新增用户私照-多张
     */
    @PostMapping("/batch")
    public List<UserCoverUrl> batchAddUserCoverUrl(Authentication token,UserCoverUrl entity) {
        Subject subject = (Subject) token.getPrincipal();
        entity.setUserId(subject.getId());
        return userCoverUrlService.batchAddUserCoverUrl(entity);
    }
}
